
layui.use(['table','form','jquery'],function () {
    var table = layui.table,
        $ = layui.jquery,
        form = layui.form;

    $("button#add").click(function () {
        var value = $("#distrAreaName").val();
        if(value == ""){
            alert("输入不能为空！！！")
        }else {
            var res = confirm("确定添加吗？");
            if(res == true){
                $.post('../../distr-area/checkArea',{data:value},function (data,status) {
                    if (data == "ture"){
                        alert("该区域已存在！！！");
                    }else {
                        $.post("../../distr-area/addArea",{data:value},function (data,status) {
                            if(data == "ture"){
                                alert("区域添加成功！！！");
                                location.reload();
                            }
                        });
                    }
                });
            }
        }
    });

    $("a#delete").click(function () {
        var res = confirm("确定删除吗？");
        if(res == true){
            return true;
        }else{
            return false;
        }
    });


    $("#submit").click(function (e) {
        var value1 = $("#update").val();
        var value2 = $("#oldName").val();
        if (value1 != "") {
            var res = confirm("确定修改吗？");
            if (res == true) {
                $.post('../../distr-area/checkArea', {data: value1}, function (data, status) {
                    if (data == "ture") {
                        alert("该区域已存在！！！");
                    } else {
                        $.post("/distr-area/reviseArea", {distrAreaName: value1, oldName: value2}, function (data) {
                            if (data == "ture") {
                                window.location.href = "/distr-area/allArea";
                            }
                        });
                    }
                });
            }
        }else {
            alert("输入不能为空！！！")
        }


    });




});